<template>
    <div class="appMarket">
      <!--  <p style="color:#333;text-indent: 20px;">
            <router-link style="color:#F56C6C;text-decoration: none;" to=""></router-link>
        </p>-->
        <p style="padding: 10px 20px;background:rgba(64,158,255,0.1);color: rgb(245, 108, 108);">
            平台统一推出“立足企业、优化资源、互联互通”的服务类产品。产品由平台准入的第三方独立运营，旨在提供外贸环节报关报检、投保理赔、退税风控等一系列在线解决方案。平台会不断筛选、升级、优化第三方运营团队及其产品，希望可以正真“惠及行业，惠及企业“。
        </p>
        <h4 class="title-text" v-if="list2.length>0">已开通</h4>
        <div class="cell-box clear">
            <div class="fl inner clear"  v-for="(item,i) in list2" :key="i">
                <div class="inner-box fl">
                    <div class="bt">
                        <div><strong>{{item.serviceName}}</strong><span v-show="false">便捷通知</span></div>
                    </div>
                    <div class="gys">
                        供应商：{{item.devSourceCompanyName}}
                    </div>
                </div>
                <div class="fl btn">
                    <div><a href="javascript:;" @click="openHandle(item.serviceId)" class="first">打开</a></div>
                    <div><router-link :to="{name:'append',query:{ serviceId: item.serviceId, serviceName: item.serviceName}}">编辑</router-link></div>
                </div>
            </div>
        </div>
        <h4 class="title-text">未开通</h4>
        <div class="box">
            <ul>
                <router-link tag="li" to="" class="clear" v-for="(item,i) in list" :key="i" v-show="item.currentState!=2">
                    <div class="fl fl_content">
                        <div class="clear top_content">
                            <h3 class="fl">{{item.serviceName}}</h3>
                            <div class="fr" style="line-height: 40px;">
                                <span style="color:#303133;">开通企业数：<span style="color:#F56C6C;">{{item.serviceCompanyNum}}</span></span>
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <span style="color:#303133;">供应商：<span style="color:#909399;">{{item.devSourceCompanyName}}</span></span>
                            </div>
                        </div>
                        <div class="des">
                            {{item.meno}}
                        </div>
                    </div>
                    <router-link :to="{name:'append',query:{ serviceId: item.serviceId, serviceName: item.serviceName}}">
                        <!--0未申请1申请中2审核通过3停止9审核失败-->

                        <el-button class="fr open_btn" type="text" v-if="item.currentState==1">申请中</el-button>
                        <el-button class="fr open_btn" type="primary" v-else-if="item.currentState==0">去开通</el-button>
                        <el-button class="fr open_btn" type="text" v-else-if="item.currentState==3">服务暂停</el-button>
                        <el-button class="fr open_btn" type="text" v-else-if="item.currentState==9">审核失败</el-button>
                    </router-link>
                </router-link>

            </ul>
        </div>
    </div>
</template>

<script>
    import {service_list} from '@/api/service'

    export default {
        data() {
            return {
                list: [],
                list2:[]
            }
        },
        watch:{
          '$route'(to,form){
              if(to.name=='market'){
                  document.getElementsByClassName('app-navbar')[0].getElementsByClassName('m-top-title')[0].style.cssText ='color:rgb(245, 108, 108)';
              }else{
                  document.getElementsByClassName('app-navbar')[0].getElementsByClassName('m-top-title')[0].style.cssText ='color:#888';
              }
          }
        },
        created() {
            this.init();
        },
        mounted(){
            document.getElementsByClassName('app-navbar')[0].getElementsByClassName('m-top-title')[0].style.cssText ='color:rgb(245, 108, 108)';

        },
        methods: {
            openHandle(id){
              window.open(`http://open.dc.zjmade.cn/page/1.0/ysfw/index/${id}?token=${localStorage.getItem('token')}`)
            },
            clickHandle(serviceId, serviceName) {
                this.$router.push({
                        name: 'append', query: {
                        serviceId: 1, serviceName: 1
                    }
                })
                console.log(this.$route)
            },
            init() {
                service_list().then(res => {
                    if (res.code == 0) {
                        let arr = [];
                        this.list = res.data;
                        res.data.forEach(function (el,i) {
                            if(el.currentState ==2){
                                arr.push(el)
                            };
                        })
                        this.list2=arr;
                    }
                }).catch(err => {
                    console.log(err)
                })
            }
        }
    }
</script>

<style scoped lang="scss">
    .title-text{
        border-left: 4px solid #2a82e4;
        margin-left: 20px;
        padding-left: 10px;
    }
    .cell-box{
        padding-left: 20px;
        .inner{
            box-shadow: 0 0 10px #ddd;
            border: 1px solid #eee;
            padding: 20px;
            border-radius: 4px;
            margin-bottom: 20px;
            margin-right: 20px;
            .inner-box{
                .bt{
                    padding-top: 10px;
                    span{
                        margin-left: 8px;
                        padding: 4px 10px;
                        border-radius: 20px;
                        font-size: 12px;
                        background: #ededed;
                    }
                }
                .gys{
                    padding-top: 4px;
                    font-size: 14px;
                }
            }
        }
        .btn{
            margin-left: 40px;
            div{
                line-height: 30px;
                .first{
                    background: #2a82e4;
                    border: none;
                    color: #fff;
                }
                a{
                    font-size: 12px;
                    border: 1px solid #aaa;
                    border-radius: 3px;
                    padding: 5px 10px;
                    text-decoration: none;
                    color: #222;
                }
            }
        }
    }
    html, body, ul, li, h3 {
        padding: 0;
        margin: 0;
    }

    .appMarket {
        .box {
            /*max-width: 1000px;*/
            li {
                border: 1px solid #DCDFE6;
                box-shadow: 0px 0px 5px #d1d3d8;
                border-radius: 4px;
                position: relative;
                /*background: #000;*/
                padding: 0;
                margin: 0;
                list-style: none;
                padding-right: 20px;
                margin-left: 20px;
                padding-left: 20px;
                margin-top: 20px;
                margin-right: 20px;
                margin-bottom: 20px;
                padding: 20px;
                h3 {
                    font-size: 20px;
                }
                .top_content {
                    border-bottom: 1px solid #DCDFE6;
                    width: 100%;
                    padding-bottom: 5px;
                    margin-bottom: 10px;
                }
                .fl_content {
                    width: calc(100% - 200px);
                }
                .open_btn {
                    right: 20px;
                    position: absolute;
                    top: 50%;
                    margin-top: -20px;
                }
                .des {

                }
            }
        }
    }

    .clear:after {
        display: block;
        content: '';
        clear: both;
    }

    .fl {
        float: left;
    }

    .fr {
        float: right;
    }


</style>